{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "dcb5be59",
   "metadata": {},
   "source": [
    "# 请求数据准备"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f303ae71",
   "metadata": {},
   "source": [
    "## header"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "727464d1",
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "module 'liepin_data' has no attribute 'data'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "Input \u001b[1;32mIn [1]\u001b[0m, in \u001b[0;36m<cell line: 2>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mliepin_data\u001b[39;00m\n\u001b[1;32m----> 2\u001b[0m \u001b[43mliepin_data\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdata\u001b[49m\n",
      "\u001b[1;31mAttributeError\u001b[0m: module 'liepin_data' has no attribute 'data'"
     ]
    }
   ],
   "source": [
    "import liepin_data\n",
    "liepin_data.data"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a1d3deea",
   "metadata": {},
   "source": [
    "* 备注"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c3cc4e46",
   "metadata": {},
   "source": [
    "> 1. 城市：'全国'、'北京'、'上海'、'天津'、'重庆'、'广州'、'深圳'、'苏州'、'南京'、'杭州'、'大连'、'成都'、'武汉'、'西安'  \n",
    "> 2. 关键词：不限制  \n",
    "> 3. 工作经验：'应届生'、'实习生'、'1年以内'、'1-3年'、'3-5年'、'5-10年'、'10年以上'"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9a547cbe",
   "metadata": {},
   "source": [
    "## payload"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "88349ae5",
   "metadata": {},
   "outputs": [],
   "source": [
    "payload = liepindata.request_payload(城市=\"深圳\",关键词=\"数据分析师\",工作经验=\"实习生\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "eb43ca40",
   "metadata": {},
   "source": [
    "# 指定数据抓取"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "19574b3a",
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "from requests_html import HTMLSession\n",
    "\n",
    "session = HTMLSession()\n",
    "r = session.post(\n",
    "            url = 'https://api-c.liepin.com/api/com.liepin.searchfront4c.pc-search-job',\n",
    "            data = json.dumps(payload), # POST请求带的参数\n",
    "            headers = headers    # 模拟真实用户\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "819688d1",
   "metadata": {},
   "outputs": [],
   "source": [
    "liepin_data = r.json()\n",
    "liepin_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7a23ff0c",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "pd.json_normalize(liepin_data['data']['data']['jobCardList'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a2bbbe54",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b0cf71a5",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9c01eacc",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ed48f8a6",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
